package com.yhk.wuchat.common.user.service.impl;

import com.yhk.wuchat.common.user.domain.enums.RoleEnum;
import com.yhk.wuchat.common.user.service.IRoleService;
import com.yhk.wuchat.common.user.service.cache.UserCache;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

/**
 * @version 1.0
 * @Author moresuo
 * @Date 2024/4/17 21:11
 * @注释
 */
@Service
public class RoleServiceImpl implements IRoleService{

    @Resource
    private UserCache userCache;
    @Override
    public boolean hasPower(Long uid, RoleEnum roleEnum) {
        Set<Long> roleSet = userCache.getRoleSet(uid);
        return isAdmin(roleSet)||roleSet.contains(roleEnum.getId());
    }
    private boolean isAdmin(Set<Long> roleSet){
        return roleSet.contains(RoleEnum.ADMIN.getId());
    }
}
